<template>
<div>
  <div>子组件：</div>
  <div>{{nameP}}</div>
  <button @click="setUser">传值</button>
</div>
  <!-- <input type="text" v-model="childValue" /> -->
</template>

<script>
export default {
  name: "HelloWorld",
  data() {
    return {
      name: '', // 关联值
      user:'子传父的内容'
    };
  },
  props: {
    nameP: String, // 接受父组件传递的值
  },
  methods: {
    setUser:function(){
       this.$emit('transfer',this.user)//触发transfer方法，this.user 为向父组件传递的数据
     }
  },
};
</script>
<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>
h3 {
  margin: 40px 0 0;
}
ul {
  list-style-type: none;
  padding: 0;
}
li {
  display: inline-block;
  margin: 0 10px;
}
a {
  color: #42b983;
}
</style>
